package yijy.company.singletonExample;

/**
 * Created by yijy on 2017/9/15.
 */
public class Quick {
    public static void main (String[] args){
        Integer[] list = {34,3,53,2,23,7,14,10,1};
        if(list.length>0){
            quicksort(list,0,list.length-1);
        }
        for(int i=0;i<list.length;i++){
            System.out.print(list[i]+"\t");
        }
    }

    public static void quicksort(Integer[] list,int  low,int high){
        if(low<high){
            int middle = getMiddle(list,low,high);
            quicksort(list,low,middle-1);
            quicksort(list,middle+1,high);
        }
    }

    public static int getMiddle(Integer[] list,int low,int high){
        int tmp = list[low];
        while(low<high){
            while(low<high && list[high]>tmp){
                high--;
            }
            list[low]=list[high];
            while(low<high && list[low]<tmp){
                low++;
            }
            list[high]=list[low];
        }
        list[low]=tmp;
        return low;
    }
}
